import {
  CircleGeometry,
  PlaneGeometry,
  MeshBasicMaterial,
  Mesh,
  DoubleSide,
} from "three";
import { getTexture } from "./texture";

const Size = 35;

export async function createMesh(user, shape) {
  const texture = await getTexture(user.avatar, 256);
  const geometry =
    shape === "Circle"
      ? new CircleGeometry(Size / 2, 30)
      : new PlaneGeometry(Size, Size);

  const material = new MeshBasicMaterial({
    color: 0xffffff,
    side: DoubleSide,
    map: texture,
  });

  const mesh = new Mesh(geometry, material);
  mesh.frustumCulled = true;

  mesh.position.set(
    Math.random() * 4000 - 2000,
    Math.random() * 4000 - 2000,
    Math.random() * 4000 - 2000
  );

  return mesh;
}
